/*******************************************************************************
 * FilePath    : \Software\Examples\MS1656_app_UART\Src\BSP\Led.c
 * Version     : 1.0
 * Brief       : 
 * Author      : AndrewHu
 * Company     : Shanghai MacroGiga Electronics CO.,Ltd
 * Email       : Hubinbo@macrogiga.com
 * Date        : 2020-04-03 15:15:31
 * LastEditors : AndrewHu
 * LastEditTime: 2020-05-25 12:10:26
 * Description : 
 ******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include <Includes.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function ----------------------------------------------------------*/
/* extern --------------------------------------------------------------------*/

/*******************************************************************************
 * Function    : Led_Init
 * Brief       : 
 * Parameter   : 
 * Returns     : 
 * Date        : 2020-04-03 16:01:38
 * Description : 
 ******************************************************************************/
void Led_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;

    __HAL_RCC_GPIOA_CLK_ENABLE();

    GPIO_InitStructure.Pin = LED_PIN;
    GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT;
    GPIO_InitStructure.OpenDrain = GPIO_PUSHPULL;
    GPIO_InitStructure.Debounce.Enable = GPIO_DEBOUNCE_DISABLE;
    GPIO_InitStructure.SlewRate = GPIO_SLEW_RATE_LOW;
    GPIO_InitStructure.DrvStrength = GPIO_DRV_STRENGTH_HIGH;
    GPIO_InitStructure.Pull = GPIO_NOPULL; //GPIO_NOPULL;
    HAL_GPIO_Init(LED_GPIO, &GPIO_InitStructure);
    HAL_GPIO_WritePin(LED_GPIO, LED_PIN, GPIO_PIN_SET); //high, off
}
/*******************************************************************************
 * Function    : LED_OnOff
 * Brief       : LED亮灭控制
 * Parameter   : 
 * Returns     : 
 * Date        : 2020-04-03 15:59:24
 * Description : 
 ******************************************************************************/
void LED_OnOff(u8 onFlag)
{
    if (onFlag)
        HAL_GPIO_WritePin(LED_GPIO, LED_PIN, GPIO_PIN_RESET); //low, on
    else
        HAL_GPIO_WritePin(LED_GPIO, LED_PIN, GPIO_PIN_SET); //high, off
}
/*******************************************************************************
 * Function    : LED_ChangeStatus
 * Brief       : LED灯的亮灭状态改变
 * Parameter   : 
 * Returns     : 
 * Date        : 2020-04-04 15:18:38
 * Description : 
 ******************************************************************************/
void LED_ChangeStatus(void)
{
    if (HAL_GPIO_ReadPin(LED_GPIO, LED_PIN))
        HAL_GPIO_WritePin(LED_GPIO, LED_PIN, GPIO_PIN_RESET); //low, on
    else
        HAL_GPIO_WritePin(LED_GPIO, LED_PIN, GPIO_PIN_SET); //high, off
}
/*******************************************************************************
 * Function    : getLedStatus
 * Brief       : 获取LED灯亮灭状态
 * Parameter   : 
 * Returns     : 
 * Date        : 2020-04-04 15:20:46
 * Description : 
 ******************************************************************************/
u8 getLedStatus(void)
{
    if (HAL_GPIO_ReadPin(LED_GPIO, LED_PIN))
        return 0;
    else
        return 1;
}
